package com.sky.controller.admin;

import com.sky.QueryByPage.SetmealPageBean;
import com.sky.dto.SetmealDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;
    @GetMapping("/page")
    public Result getByPage(SetmealPageBean pageBean){
        PageResult result = setmealService.getByPage(pageBean);
        return Result.success(result);
    }

    @PostMapping
    public Result add(@RequestBody SetmealDTO setmealDTO){
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        SetmealVO setmealVO =  setmealService.getById(id);
        return Result.success(setmealVO);
    }


    @PostMapping("/status/{status}")
    public Result status(@PathVariable Integer status,@RequestParam Integer id){
        setmealService.status(status,id);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        setmealService.delete(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }

}
